package com.gx.smart.building.ui.common.util;

import java.util.Calendar;

/**
 * @author xiaosy
 * @create 2020/9/4
 * @Describe 日期的获取
 **/
@SuppressWarnings("unused")
public class DateUtils {
    public static long getMondayOfThisWeek() {
        Calendar c = Calendar.getInstance();
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0) {
            day_of_week = 7;
        }
        c.add(Calendar.DATE, -day_of_week + 1);
        return c.getTimeInMillis();
    }

    public static long getFirstDayOfThisMonth() {
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR),
                startDate.get(Calendar.MONTH),
                startDate.getActualMinimum(Calendar.DAY_OF_MONTH),
                00,
                00, 00);
        return startDate.getTimeInMillis();
    }

    /**
     * 获取昨天时间
     *
     * @return
     */
    public static long getYesterdayStartDate() {
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR),
                startDate.get(Calendar.MONTH),
                startDate.get(Calendar.DAY_OF_MONTH) - 1,
                00,
                00, 00);
        return startDate.getTimeInMillis();
    }

    /**
     * 获取昨天时间
     *
     * @return
     */
    public static long getYesterdayEndDate() {
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR),
                startDate.get(Calendar.MONTH),
                startDate.get(Calendar.DAY_OF_MONTH) - 1,
                23,
                23, 59);
        return startDate.getTimeInMillis();
    }

    /**
     * 获取明天时间
     *
     * @return
     */
    public static Calendar getTomorrowStartDate() {
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR),
                startDate.get(Calendar.MONTH),
                startDate.get(Calendar.DAY_OF_MONTH) + 1,
                00,
                00, 00);
        return startDate;
    }


    /**
     * 获取前天时间
     *
     * @return
     */
    public static long getBeforeYesterdayStartDate() {
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR),
                startDate.get(Calendar.MONTH),
                startDate.get(Calendar.DAY_OF_MONTH) - 2,
                00,
                00, 00);
        return startDate.getTimeInMillis();
    }

    /**
     * 获取前天时间
     *
     * @return
     */
    public static long getBeforeYesterdayEndDate() {
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR),
                startDate.get(Calendar.MONTH),
                startDate.get(Calendar.DAY_OF_MONTH) - 2,
                23,
                23, 59);
        return startDate.getTimeInMillis();
    }

    /**
     * 上个月
     *
     * @return 时间戳
     */
    public static long getLastedMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return calendar.getTimeInMillis();
    }

}
